package tech.eyao.hs60x.dao;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import tech.eyao.hs60x.mapper.ApprovalDOMapper;
import tech.eyao.hs60x.model.domain.ApprovalDO;
import tech.eyao.hs60x.vo.ApprovalPageQuery;

/**
 * 绑定权限表
 * 
 * @author hejian
 * @date 2018年1月12日 上午11:38:42
 */
@Repository
public class ApprovalDao {

    @Autowired
    private ApprovalDOMapper approvalDOMapper;

    /**
     * 保存申请记录
     * 
     * @param approvalDO
     * @return
     */
    public boolean insert(ApprovalDO approvalDO) {
        approvalDO.setGmtCreated(new Date());
        approvalDO.setGmtModified(new Date());
        return approvalDOMapper.insert(approvalDO) > 0;
    }

    public ApprovalDO selectByPrimaryKey(Long id) {
        return approvalDOMapper.selectByPrimaryKey(id);
    }

    public List<ApprovalDO> getListByPage(ApprovalPageQuery pageQuery) {
        return approvalDOMapper.getListByPage(pageQuery);
    }

    public boolean updateByPrimaryKey(ApprovalDO approvalDO) {
        approvalDO.setGmtModified(new Date());
        return approvalDOMapper.updateByPrimaryKey(approvalDO) > 0;
    }

    /**
     * 是否已经存在申请
     * 
     * @param watchId
     * @param userId
     * @return
     */
    public boolean isHas(Long watchId, Long userId, int status) {
        return null != approvalDOMapper.isHas(watchId, userId, status);
    }
    
    /**
     * 删除审批信息
     * @param userId
     * @param watchId
     */
	public void deleteByOwnIdAndWatchId(long userId, Long watchId) {
		approvalDOMapper.deleteByOwnIdAndWatchId(userId, watchId);
	}
	/**
	 * 获取当前账户下挂所有审批信息
	 * @param userId
	 * @param watchId
	 * @return
	 */
	public List<ApprovalDO> getListByCondition(Long userId, Long watchId) {
        return approvalDOMapper.getListByCondition(userId,watchId);
    }
}
